// map.js
Page({
  data: {
    latitude: 40.060539,
    longitude: 116.343847,
    // 列表信息
    appointment: "",
    attachment: [],
    description: "",
    houseId: "",
    houseInfo: "",
    id: "",
    mobile: "",
    repairItemId: "",
    repairItemName: "",
    status: 0,
    // 地图标记
    /* 
    1. markers 是一个数组，里面存放每一个点的经纬度等信息
    2. 经纬度和 宽高 必有，id也建议有，iconPath可以设置标记的图片
    3. 如果看不到，请把地图缩放，并且检查自己传进去的经纬度
    */
    markers: [
      {
        // id: 1,
        id: 1,
        width: 40,
        height: 30,
        iconPath: '../../../static/images/marker.png',
        latitude: 31.818434,
        longitude: 117.234169,
      },
      {
        id: 2,
        latitude: 31.818434,
        longitude: 117.235169,
        width: 40,
        height: 30,
        iconPath: '../../../static/images/marker.png'
      },
    ],
    // polyline 把点连成线，一般实现地图的路线导航
    // 数组包裹住对象，每一个对象都是一根线
    // 对象核心属性 points: [{经纬度的点},{经纬度的点}], width一定要有
    polyline: [
      {
        width: 4,
        color: '#07c160',
        dottedLine: true,
        colorList: ['#1e88da', '#6a9955', '#dbd700', '#ce9178', '#487e02'],
        points: [
          {
            latitude: 31.818234,
            longitude: 117.235169,
          },
          {
            latitude: 31.819434,
            longitude: 117.275169,
          },
          {
            latitude: 31.819434,
            longitude: 117.255169,
          },
          {
            latitude: 31.817434,
            longitude: 117.285169,
          },
          {
            latitude: 31.828434,
            longitude: 117.265169,
          },
        ],
      }
    ],
  },
  onLoad({ id }) {
    console.log(id);
    this.getRepdetail(id)
  },
  async getRepdetail(id) {
    const res = await wx.http({
      url: `/repair/${id}`
    })
    console.log(res);
    this.setData({ ...res.data })
    //地址解析
    this.geocoder()
  },
  geocoder() {
    wx.qqmap.geocoder({
      address: "安徽省合肥市瑶海区" + this.data.houseInfo,
      success: (res) => {
        console.log(res);
        this.setData({
          latitude: res.result.location.lat,
          longitude: res.result.location.lng
        })
      }
    })
  }
})
